package com.inspur.ourhis_afterend.Service.Impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inspur.ourhis_afterend.Dao.MemberDao;
import com.inspur.ourhis_afterend.Entity.Member;
import com.inspur.ourhis_afterend.Service.PaymentDetailsServie;
import com.inspur.ourhis_afterend.mapper.PaymentDetailsMapper;
import com.inspur.ourhis_afterend.model.PaymentDetails;
import com.inspur.ourhis_afterend.vo.PaymentDetailsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("paymentDetailService")
public class PaymentDetailsServiceImpl implements PaymentDetailsServie {
    @Resource
    PaymentDetailsMapper paymentDetailsMapper;
    @Autowired
    MemberDao memberDao;


    @Override
    public IPage<PaymentDetailsVo> SelectBySelective(IPage<PaymentDetailsVo> page, Integer memberid) {
        return paymentDetailsMapper.SelectBySelective(page,memberid);
    }

    @Override
    public int add(PaymentDetails paymentDetails) throws Exception {
        Member member = memberDao.selectById(paymentDetails.getMemberid());
        paymentDetails.setBalance(member.getBalance());
        memberDao.increase(member.getMemberid(), paymentDetails.getRechargeamount());
        System.out.println(paymentDetails);
        return paymentDetailsMapper.insert(paymentDetails);
    }
}
